package com.demo.webflux.jpaadapter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

@RestController
public class BookController {

	private static Logger logger = LoggerFactory.getLogger(BookController.class);
	private Scheduler scheduler = Schedulers.newParallel("jpa", 10);
	@Autowired
	private BookJpaRepository jpaRepository;

	// 将阻塞式包装成响应式
	@GetMapping("/find1")
	public Flux<Book> findByIdBetween(){
		RxBookRepository rx = new RxBookRepository(jpaRepository, scheduler);
		return rx.findByIdBetween(Mono.just(17), Mono.just(22));
	}

}
